﻿using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;

namespace GX
{
    public enum AssetStatus
    {
        None,
        Wait,
        Loading,
        WaitDependency,
        Done,
    }
    public delegate void AssetDelegate(IAssetInfo assetInfo);

    public interface IAssetInfo
    {
        string path { get; }
        bool isDone { get; }
        string error { get; }
        float progress { get; }
        Object LoadAsset(string name);
        Object GetAsset();
        Object[] GetAllAssets();
        byte[] bytes { get; }
        string text { get; }
    }
	public interface IAssetManager:IService
	{
        void Initalize(MonoBehaviour behaviour, IAssetManifest assetManifest);
        void Load(string assetPath, AssetDelegate onDone, AssetDelegate onProgress);
        void LoadBytes(string assetPath, AssetDelegate onDone, AssetDelegate onProgress);
        void LoadText(string assetPath, AssetDelegate onDone, AssetDelegate onProgress);
        void Unload(string assetPath, AssetDelegate onDone, AssetDelegate onProgress);
        void Retain(string assetPath);
        void Release(string assetPath);
        void UnloadUnUsedAssets();
	}

    public interface IAssetManifest
    {
        /// <summary>
        /// 是否开启AssetBundle模式，如果不开启，就用Resource
        /// </summary>
        bool enableAssetBundle { get; }
        /// <summary>
        /// 当stream路径下找不到资源是否在persist路径查找，仅在AssetBundle模式下有效
        /// </summary>
        bool searchPersistPath { get; }
        /// <summary>
        /// 当在本地stream和persist路径都找不到，是否从远程加载，仅在AssetBundle模式下有效
        /// </summary>
        bool enableRemoteLoad { get; }
        /// <summary>
        ///是否开启persist路径的cache，如果开启了并且当前平台支持文件系统，加载的bundle会被缓存到本地，仅在AssetBundle模式下有效
        /// </summary>
        bool enalbePersistCache { get; }
        int tryLoadCount { get; }
        string resourcePath { get; }
        string streamPath { get; }
        string persistPath { get; }
        string remotePath { get; }
        bool existsInStream { get; }
        bool existsInPersist { get; }
        bool existsInNewest { get; }
        int numLoadWorks { get; }
        int delayUnloadSeconds { get; }
        bool TryGetAssetBundleName(string assetPath, out string name);
        string GetAssetBundleName(string assetPath);
        string[] GetDirectDependencies(string assetBundleName);
        string[] GetAllDependencies(string assetBundleName);
        int GetAssetBundleDirectUsageCount(string assetBundleName);
        void OnCacheAsset(string path);
    }
}